package com.baicaoyuan.web.controller;


import com.baicaoyuan.web.common.LogUtil;
import com.baicaoyuan.web.common.Status;
import com.baicaoyuan.web.common.annotation.MemberAccess;
import com.baicaoyuan.web.common.exception.StateMessage;
import com.baicaoyuan.web.request.br.BStockApplyIdRequest;
import com.baicaoyuan.web.request.br.BStockApplyPageRequest;
import com.baicaoyuan.web.request.br.BStockApplyRequest;
import com.baicaoyuan.web.response.StockApplyResponse;
import com.baicaoyuan.web.service.StockApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@Api(value = "股东申请Controller", tags = {"股东申请审核操作接口"})
@RestController
@RequestMapping(value = "/stockApply")
public class StockApplyController {

    @Autowired
    StockApplyService stockholderService;

    @ApiOperation(value = "股东-申请（token）", notes = "", code = 200, produces = "application/json")
    @RequestMapping(value = "/saveStockApply", method = RequestMethod.POST)
    @MemberAccess
    @ResponseBody
    public Status saveStockApply(@RequestBody BStockApplyRequest request) {
        try {
            stockholderService.save(request);
            Status result = new Status(StateMessage.SUCCESS);
            return result;
        } catch (Exception ex) {
            LogUtil.Error("", ex);
            return new Status(StateMessage.FAILED);
        }
    }

    @ApiOperation(value = "股东-审核（token）", notes = "", code = 200, produces = "application/json")
    @RequestMapping(value = "/updateStockApplyStatus", method = RequestMethod.POST)
    @MemberAccess
    @ResponseBody
    public Status updateStockApplyStatus(@RequestBody BStockApplyIdRequest request) {
        try {
            this.stockholderService.updateStatus(request.getId(), request.getStatus());
            Status result = new Status(StateMessage.SUCCESS);
            return result;
        } catch (Exception ex) {
            LogUtil.Error("", ex);
            return new Status(StateMessage.FAILED);
        }
    }

    @ApiOperation(value = "后台-获取股东申请列表", notes = "", code = 200, produces = "application/json")
    @RequestMapping(value = "/getStockApplyList", method = RequestMethod.POST)
    @MemberAccess
    @ResponseBody
    public Status getStockApplyList(@RequestBody BStockApplyPageRequest request) {
        try {
            List<StockApplyResponse> sh = this.stockholderService.getStockApply(request.getPage(), request.getSize(), request.getStatus());
            Integer count = this.stockholderService.getCountOfAll(request.getStatus());
            Status result = new Status(StateMessage.SUCCESS);
            result.setData("stockApplyList", sh);
            result.setData("totalCount", count);
            return result;
        } catch (Exception ex) {
            LogUtil.Error("", ex);
            return new Status(StateMessage.FAILED);
        }
    }
}
